package com.tmeone.erpone.controller;

import com.tmeone.erpone.entity.*;
import com.tmeone.erpone.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
import java.util.UUID;

/**
 * 出入库管理里面的入库添加
 */
@RestController
public class InAndOutController {

    @Autowired
    private ITWareService wareService;

    @Autowired
    private ITProductService productService;

    @Autowired
    private ITShelvesService shelvesService;

    @Autowired
    private ITCargoService cargoService;

    @Autowired
    private ITIoWarehouseService ioWarehouseService;
    //查询仓库名称
    @GetMapping("/WName")
    public JsonResult getWare(){
        List<TWare> wname = wareService.list();
        return new JsonResult(1,wname);
    }

    //查询所有的商品
    /*@GetMapping("/products")
    public JsonResult getProducts(){
        List<TProduct> products = productService.list();
        return new JsonResult(1,products);
    }*/

    //根据id查询单条商品
    @GetMapping("/product/{id}")
    public JsonResult getProductById(@PathVariable String id){
        List<Product> product = productService.selectProductById(id);
        return new JsonResult(1,product);
    }

    //根据wareId查询货区
    @GetMapping("/shelvesNos/{wareId}")
    public JsonResult getShelvesByWareId(@PathVariable String wareId){
        List<TShelves> shelvesNos = shelvesService.selectShelvesByWareId(wareId);
        return new JsonResult(1,shelvesNos);
    }

    //根据shelvesId查询货架
    @GetMapping("/cargoByShelvesId/{shelvesId}")
    public JsonResult getCargoByShelvesById(@PathVariable String shelvesId){
        List<TCargo> cargoNo = cargoService.selectByShelvesId(shelvesId);
        return new JsonResult(1,cargoNo);
    }

    //入库添加
    @PostMapping("/saveIN")
    public JsonResult saveIN(@RequestBody TIoWarehouse ioWarehouse){
        ioWarehouse.setIoTime(LocalDate.now());
        ioWarehouse.setId(UUID.randomUUID().toString().replace("-","").substring(0,10));
        boolean save = ioWarehouseService.save(ioWarehouse);
        return new JsonResult(1,save);
    }
}
